home *** CD-ROM | disk | FTP | other *** search
/ PC-SIG Library 8 / PC-SIG Library CD-ROM (8th Edition) (1990-04).iso / 001_100 / disk0048 / datafix.bas (.txt) < prev    next >
Encoding:
GW-BASIC  |  1980-01-01  |  7.0 KB  |  153 lines

  1. 100  'DATAFIX
  2. 120  '
  3. 140  'BY         Art Schneider Feb 8,1982
  4. 150  '           Boston Computer Society, IBM Personal Computer Users Group
  5. 160  '
  6. 180  'DESCRIPTION:   Utility program for Sequential data files!
  7. 200  '
  8. 220  '           1.  For line line numbered data files this program
  9. 240  '           strips off line numbers {and or leading  <',>
  10. 260  '           characters} from the data line and saves the remaining
  11. 280  '           full data line in a new file.  The line numbered file
  12. 300  '           must have been saved in ASCII (A'option)
  13. 320  '
  14. 340  '           2.  For convential data files (with out line numbers)
  15. 360  '           this program will add a leading line number and <',>
  16. 380  '           {remark format}.  The new line numbered file may be
  17. 400  '           loaded and edited in BASIC
  18. 420  '
  19. 440  'INSTRUCTIONS:  Run program and respond to questions.
  20. 460  '           Questions relate to choice 1 or 2 as noted above;
  21. 480  '           the names of input and output files;  and if you wish
  22. 500  '           to see on the screen the file modification as it occurs.
  23. 510  '
  24. 515  'REFERENCE:    "DIRECT TYPED SEQUENTIAL DATA FILES"
  25. 517  '
  26. 520  '           Type and edit data files with the full Screen Basic Editor!
  27. 522  '
  28. 525  '           A 15 page report on how to use this program with sequential
  29. 527  '           data files is available.  SEND $1.00 to:
  30. 530  '           Art Schneider   8 Melanie Ln    Mattapoisett MA 02739
  31. 540  '
  32. 560  'LANQUAGE:      BASIC  IBM Personal Computer (microsoft) Disk
  33. 570  '
  34. 580  '...................................   INITIALIZE   ................
  35. 600  '
  36. 620  SCREEN 0,0 : CLS : CLOSE            'set up & clear
  37. 640  DEFINT A-Z : WIDTH 80 : K =0
  38. 660  KEY OFF : TB = 10 : C$ =""
  39. 680  FALSE = 0 : TRUE = NOT FALSE
  40. 700  PRINT TAB(TB+10);
  41. 720  COLOR 0,7 :PRINT "SEQUENTIAL  DATA  FILE  UTILITY  DATAFIX"
  42. 740  PRINT : COLOR 15,0                  'bright screen
  43. 760  PRINT TAB(TB);"Select option to ADD or REMOVE line numbers from data file"
  44. 780  PRINT : PRINT TAB(TB); "A = Add  R = Remove ";:INPUT "[A or R]";S$
  45. 800  PRINT
  46. 820  PRINT TAB(TB);"Do you want the as modified file also listed on the screen;"
  47. 840  PRINT TAB(TB);:INPUT "{ LIST ... Y or N }";P$
  48. 860  IF P$="Y" OR P$ ="y" THEN P = TRUE  'yes do a screen list
  49. 880  IF S$ ="A" OR S$="a" THEN 1600      'add line utility
  50. 900  IF S$ ="R" OR S$="r" THEN 960       'remove line
  51. 920  PRINT S$; " ain't A or R ":GOTO 780
  52. 940  '
  53. 960  '................................   REMOVE  LINE NUMBERS  UTILITY  ...
  54. 1000  COLOR 7,0 : PRINT
  55. 1020  PRINT "Remove line numbers from......"
  56. 1040  INPUT "Line numbered data file name...d:Name.Ext ";L$
  57. 1060  ON ERROR GOTO 2260                 'process open error
  58. 1080  OPEN "I",#1,L$                     'input file with line #
  59. 1100  PRINT "input File.... ";L$;" found"
  60. 1120  PRINT
  61. 1140  PRINT "State file format  1,2,3"
  62. 1160  PRINT "1 = Direct  2 = Comma  3 = Remark  (4=HELP)";
  63. 1180  INPUT "   {1,2,3 or 4} ";F
  64. 1200  IF F = 4 THEN GOTO 2600            'help - explain format
  65. 1220  IF F=1 THEN C$ = " " ELSE C$ = CHR$(44) ' 1 =blank 2&3 = comma
  66. 1240  PRINT
  67. 1260  PRINT "If you name a presaved output file we will append to it!!"
  68. 1280  INPUT "Name of file without line #.......d:Name.Ext   ";D$
  69. 1300  ON ERROR GOTO 2380                 'open file error
  70. 1320  OPEN "A",#2,D$                     'with optional Append
  71. 1340  PRINT "output file ";D$ ; " ready"
  72. 1360  LOCATE 25,30                       'reserved 25th line
  73. 1380  COLOR 18,0: PRINT " processing file " ' Blink it
  74. 1400  COLOR 7,0                          'normal screen
  75. 1420  WHILE NOT EOF(1)                   'close & end
  76. 1440  LINE INPUT #1,A$                   'read full data line
  77. 1460  B = INSTR(1,A$,C$)                 'locate 1st delimeter
  78. 1480  K = K+1                            'count the lines
  79. 1500  B$ = RIGHT$(A$,LEN(A$)-B)          'the desired full data string
  80. 1520  PRINT #2,B$                        'save data string in D$ file
  81. 1540  IF P OR K <2 THEN PRINT B$         'list all or atleast one line
  82. 1560  WEND                               'continue for the length of file
  83. 1580  GOTO 2740
  84. 1600  '..................  ADD LINE NUMERS AND <',>  UTILITY  ...........
  85. 1640  COLOR 7,0 : PRINT
  86. 1660  PRINT "Add line numbers and <',> to data in file...."
  87. 1680  INPUT "Data file name....d:Name.Ext  ";L$
  88. 1700  ON ERROR GOTO 2320
  89. 1720  OPEN "I" ,#1,L$                    'input a sequential data file
  90. 1740  PRINT : PRINT "File ...." L$ " Found"
  91. 1760  PRINT
  92. 1780  PRINT "If you name a presaved file next, we will destroy old values!!"
  93. 1800  INPUT "Line numbered data file ... d:Name.Ext";D$
  94. 1820  ON ERROR GOTO 2440                 'open error trap
  95. 1840  OPEN "O",#2,D$                     'file with line numbers
  96. 1860  PRINT : PRINT "Output file " D$ " Ready"
  97. 1880  PRINT : ON ERROR GOTO 2500         'trap large data line
  98. 1900  LOCATE 25,30
  99. 1920  COLOR 18,0 : PRINT " processing file"
  100. 1940  COLOR 7,0
  101. 1960  LINENUM= 990 : INC=10              '1st line number & increment
  102. 1980  R$ =" "+CHR$(39)+","               'remark format < ',>
  103. 2000  WHILE NOT EOF(1)                   'close and end
  104. 2020  LINE INPUT #1,A$                   'read full data line
  105. 2040  LINENUM = LINENUM + INC            'the line number
  106. 2060  'drop leading numeric line number blank by string conversion
  107. 2080  LINES$ =RIGHT$(STR$(LINENUM),4) + R$ 'line number string
  108. 2100  B$ = LINES$ + A$                   'put them together
  109. 2120  K = K + 1                          'counter
  110. 2140  PRINT #2,B$                        'load the file
  111. 2160  IF P OR K <2 THEN PRINT B$         'list all or atleast one line
  112. 2180  WEND                               'continue
  113. 2200  GOTO 2740
  114. 2220  '......................  ERROR  TRAPS  .......................
  115. 2240  '
  116. 2260  IF ERR= 53 OR ERR=64 THEN PRINT "I Can't find file ";L$ : RESUME 1040
  117. 2280  IF ERR= 68 OR ERR=71 THEN PRINT "check disk & retype name":RESUME 1040
  118. 2300  ON ERROR GOTO 0            'halt on any other error
  119. 2320  IF ERR= 53 OR ERR=64 THEN PRINT "I Can't find file ";L$ : RESUME 1640
  120. 2340  IF ERR= 68 OR ERR=71 THEN PRINT "check disk & retype name":RESUME 1640
  121. 2360  ON ERROR GOTO 0            'halt on any other error
  122. 2380  IF ERR= 53 OR ERR= 64 THEN PRINT "I Can't open file ";D$ : RESUME 1240
  123. 2400  IF ERR= 68 OR ERR=71 THEN PRINT "check disk & retype name":RESUME 1240
  124. 2420  ON ERROR GOTO 0            'halt on any other error
  125. 2440  IF ERR= 53 OR ERR= 64 THEN PRINT "I Can't open file ";D$ : RESUME 1760
  126. 2460  IF ERR= 68 OR ERR=71 THEN PRINT "check disk & retype name":RESUME 1760
  127. 2480  ON ERROR GOTO 0            'halt on any other error
  128. 2500  IF ERR = 15 THEN RESUME 2520 ELSE ON ERROR GOTO 0
  129. 2520  PRINT
  130. 2540  PRINT TAB(TB) "You have a very big line and I can't add the line number"
  131. 2560  PRINT :PRINT A$            'big line
  132. 2580  PRINT : PRINT "So I have to halt":GOTO 2740
  133. 2600  PRINT :PRINT "    By format we mean the first characters after the line number" : PRINT "Your line numbered file should be in one of the following forms:"
  134. 2620  PRINT
  135. 2640  PRINT "    1. DIRECT  a string data value follows the line number."
  136. 2660  PRINT "    2. COMMA   a <,> follows the line number."
  137. 2680  PRINT "    3. REMARK  the two <',> characters follow the line number."
  138. 2700  GOTO  1120                 'repeat the question
  139. 2710  '
  140. 2720  '.........................  CLOSE  AND  END  .....................
  141. 2740  CLOSE     'all data files
  142. 2760  PRINT : PRINT : COLOR 15,0
  143. 2780  PRINT TAB(TB) K "  Data Lines Processed into " CHR$(34) D$;
  144. 2800  IF INSTR(1,D$,".") THEN PRINT CHR$(34) ELSE PRINT ".   " CHR$(34)
  145. 2820  RD1 = VAL(MID$(TIME$,4,2))*540     'use clock for random seed
  146. 2840  RD2 = VAL(MID$(TIME$,7,2))*100
  147. 2860  RANDOMIZE RD1-RD2
  148. 2880  FOR J = 1 TO 5
  149. 2900  SOUND RND*1000+37,4        'random sound at end
  150. 2920  NEXT J : SOUND 100,0 : COLOR 7,0
  151. 2940  KEY ON : ON ERROR GOTO 0   'must also end open error traps
  152. 2960  END                        'by Art Schneider (617) 993-2621
  153.